from collections import deque

class BiTreeNode:
    def __init__(self,data):
        self.data=data
        self.leftchild=None #左孩子
        self.rightchild=None#右孩子

#前序遍历
def pre_order(root):
        if root:
            print(root.data,end=",")#先根节点
            pre_order(root.leftchild)#再左子树
            pre_order(root.rightchild)#后右子树
#中序遍历
def in_order(self,root):
    if root:
        self.in_order(root.leftchild)#先左子树
        print(root.data,end=".")#再根节点
        self.in_order(root.rightchild)#后右子树
#后序遍历
def post_order(self,root):
    if root:
        self.ost_order(root.leftchild)#先左子树
        self.post_order(root.rightchild)#后右子树
        print(root.data,end=",")#后根节点
#层序遍历
def level_order(root):
    queue=deque()
    queue.append(root)
    while len(queue)>0:#只要队不空
        node=queue.popleft()
        print(node.data,end=",")
        if node.leftchild:
            queue.append(node.leftchild)
        if node.rightchild:
            queue.append(node.rightchild)


if __name__=="__main__":
    a=BiTreeNode("A")
    b=BiTreeNode("B")
    c=BiTreeNode("C")
    d=BiTreeNode("D")
    e=BiTreeNode("E")
    f=BiTreeNode("F")
    g=BiTreeNode("G")
    e.leftchild=a#前面是后面的父亲
    e.rightchild=g
    a.rightchild=c
    c.leftchild=b
    c.rightchild=d
    g.rightchild=f
    root=e
    pre_order(root)
    #in_order(root)
    #post_order(root)
    #level_order(root)